import java.sql.*;

public class GetBidServerItemIDs {
    public static void main(String[] args) {

        if (args.length < 2)
        {
            System.out.println("USAGE: java -cp .:/usr/share/java/* GetBidServerItemIDs root password");
            return;
        }
        String url = "jdbc:mysql://localhost:3306/bidsys";  
        String driver="com.mysql.jdbc.Driver";

        listItems (driver, url, args[0], args[1]);
    }

    public static void listItems(String driver, String url,
        String username, String password)
    {
    	Connection conn = null;
    	Statement statement = null;
        try {
            Class.forName(driver).newInstance();  // Register the JDBC driver

            //password=null;  // If you haven't set one for MySQL root user.
            conn = DriverManager.getConnection(
                url, username, password);

            //System.out.println ("Item Table\n");

            statement = conn.createStatement();
            String query = "SELECT item_id FROM items";

            ResultSet rst = statement.executeQuery(query);

            ResultSetMetaData rstMetaData = rst.getMetaData();

            int columnCount = rstMetaData.getColumnCount();
            /*
            for (int i = 1; i < columnCount+1; i++) {
                System.out.print(rstMetaData.getColumnName(i) + " ");
            }

            System.out.println();
            */
            while(rst.next()) {
	            for (int i = 1; i < columnCount+1; i++) 
                	System.out.print("["+ rst.getString(i) + "]-");
            }
            System.out.println("");	
        } catch (ClassNotFoundException cnfe) {
            System.out.println("Error Loading Driver: " + cnfe);
        } catch (SQLException sqle) {
            System.out.println("SQL Error: " + sqle);
        } catch (Exception e) {
            System.out.println("Error: " + e);
        } finally {
            try {
                if (statement != null)
                    statement.close();
                if (conn != null)
                    conn.close();
            } catch (SQLException sqle) {
                sqle.printStackTrace();
            }
        }
    }
}

